import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router';
import routes from './routes';
import { getToken } from '../util/authToken';
import whiteNames from './whiteRouterList';

const router = createRouter({
    // 再electron 打包时候要使用 hash模式
    history: createWebHashHistory(),
    routes
})

router.beforeEach((to, from) => {
    if (whiteNames.includes(to.name)) return true;
    if (!getToken()) {
        return to.name !== 'Login' ? { name: 'Login' } : true;
    } else {
        return to.name === 'Login' ? { path: '/' } : true;
    }
});



export default router;